<?php

class Application_Form_Product extends Zend_Form
{

    public function init()
    {
        /* Form Elements & Other Definitions Here ... */
            $catgoryObj=new Application_Model_Category();
            $catgory_list=$catgoryObj->getCategoriesList();
             $this->addElement('text', 'name', array(
                            'label' => 'Product Name',
                           // 'name'=>'catName',
                            'required' => true,
                            'filters' => array('StringTrim'),
                            'validators' => array( 'Alnum')
                        )
                );
                $this->addElement('textarea', 'discripion', array(
                            'label' => 'Product discription',
                            'rows'=>10,
                            'required' => true,
                            'filters' => array('StringTrim'),
                            'validators' => array( 'Alnum')
                        )
                );
                $this->addElement('text', 'price', array(
                            'label' => 'Product price',
                           // 'name'=>'catName',
                            'required' => true,
                            'filters' => array('StringTrim'),
                            'validators' => array( 'Alnum')
                        )
                );
                $this->addElement('text', 'quantity', array(
                            'label' => 'Product quantity',
                           // 'name'=>'catName',
                            'required' => true,
                            'filters' => array('StringTrim'),
                            'validators' => array( 'int')
                        )
                );

                //         $this->addElement('select','category_id',$catgory_list[0]);
                //category
                $cat = new Zend_Form_Element_Select('category_id');
                $cat ->setLabel('catgory')->addMultiOptions($catgory_list);
                $cat->setValidators(array(new Zend_Validate_Db_RecordExists(array('table'=>'category','field'=>'id'))));
                $this->addElement($cat);

                //image
                $image = new Zend_Form_Element_File('image');
                $image->setLabel('Upload an image:')
                      ->setDestination('product_image_large')
                      ->setRequired(true)
                      ->setMaxFileSize(1024000) // limits the filesize on the client side
                      ->setDescription('Click Browse and click on the image file you would like to upload');
                $image->addValidator('Count', false, 1);                // ensure only 1 file
                $image->addValidator('Size', false, 1024000);            // limit to 10 meg
                $image->addValidator('Extension', false, 'jpg,jpeg,png,gif');// only JPEG, PNG, and GIFs
                $image->addValidator('MimeType', false , array('image/jpeg','image/gif'));
               // $image->addFilter(array())
                $this->addElement($image);

                
                $this->setEnctype(Zend_Form::ENCTYPE_MULTIPART);
                $this->addElement('submit', 'submit', array(
                            'ignore'   => true,
                            'label'    => 'save',
                        )
                 );
    }


}

